package com.common.springbootcommonmessage.utils;


import org.apache.commons.lang3.time.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


/**
 * @ClassName: MyDateUtils
 * @Description: 日期工具类
 * @date 2018年5月29日 上午12:43:33
 */
public class DateUtil extends DateUtils {

    /**
     * 取得指定日期格式的字符串
     *
     * @param date
     * @return String
     */
    public static String formatDate(Date date, String format) {
        if(date == null) return "";
        SimpleDateFormat dateFormat = new SimpleDateFormat(format,Locale.ENGLISH);
        return dateFormat.format(date);
    }


    public static Double getTimeDiffer(Date startTime, Date endTime) {

        Double timeDiffer = 0d;
        Long time1 = startTime.getTime();
        Long time2 = endTime.getTime();

        Long diff;
        if (time1 < time2) {
            diff = time2 - time1;
        } else {
            diff = time1 - time2;
        }
        timeDiffer = Double.valueOf(diff.doubleValue());
        return timeDiffer;
    }
}